#define PWM_FREQUENCY 300 // in Hz  
#define PWM_PRESCALER 8  
#define PWM_COUNTER_PERIOD (F_CPU/PWM_PRESCALER/PWM_FREQUENCY) 

void setup()
{
  pinMode(9, OUTPUT);  
  TCCR1A = (1<<WGM11)|(1<<COM1A1)|(1<<COM1B1);  
  TCCR1B = (1<<WGM13)|(1<<WGM12)|(1<<CS11);  
  ICR1 = PWM_COUNTER_PERIOD;  
  TCCR2A = (1<<WGM20)|(1<<WGM21)|(1<<COM2A1)|(1<<COM2B1); // Clear OCnA/OCnB on compare match, set OCnA/OCnB at BOTTOM (non-inverting mode)  
  TCCR2B = (1<<CS22)|(1<<CS21); // Prescaler set to 256, that gives us a resolution of 16us  


  OCR2B = 900 / 16 ; // 1000-2000 to 128-256 
  OCR1A = 900 * 2 ;  
  OCR1B = 900 * 2 ;  
  OCR2A = 900 / 16 ;  

  while(millis() < 5000){
  }

}

void loop()
{
  for (int i=900;i<2000;i++){  
  OCR2B = i / 16 ; // 1000-2000 to 128-256 
  OCR1A = i * 2 ;  
  OCR1B = i * 2 ;  
  OCR2A = i / 16 ;  
    delay(10);
  }
  delay(500);
  for (int i=2000;i>900;i--){  
  OCR2B = i / 16 ; // 1000-2000 to 128-256 
  OCR1A = i * 2 ;  
  OCR1B = i * 2 ;  
  OCR2A = i / 16 ;  
    delay(10);
  }
  delay(500);
}  


